<?php
namespace app\admin\controller;

use think\Controller;
use app\admin\service\OrderService;

class Order extends Controller
{
    private $orderService;

    /**
     * 依赖注入 Service
     *
     * @param OrderService $orderService
     * @author zws
     */
    public function __construct(OrderService $orderService)
    {
        $this->orderService = $orderService;
        parent::__construct();
    }

    /**
     * 工单列表
     * @return \think\response\Json
     * @author zws
     */
    public function index()
    {
        $input = $this->request->input;
        $result = $this->orderService->index($input);
        return app_response(200, $result);
    }

    /**
     * 添加
     * @return \think\response\Json
     * @author zws
     */
    public function add()
    {
        $input = $this->request->input;
        $result = $this->orderService->add($input);
        return app_response(200, $result);
    }
    /**
     * 获取工单信息
     * @return \think\response\Json
     * @author zws
     */

    public function edit(){
        $input = $this->request->input;
        $result = $this->orderService->edit($input);
        return app_response(200, $result);
    }

    /**
     * 编辑工单信息
     * @return \think\response\Json
     * @author zws
     */
    public function update(){
        $input = $this->request->input;
        $result = $this->orderService->update($input);
        return app_response(200, $result ? '操作成功' : '操作失败');
    }

    /**
     * 工单详情
     * @return \think\response\Json
     * @author zws
     */
    public function detail()
    {
        $input = $this->request->input;
        $result = $this->orderService->detail($input);
        return app_response(200, $result ? '操作成功' : '操作失败');
    }

    /**
     * 获取工单属性列表值
     * User: zhouyao
     * Date: 2018/9/11
     * Time: 下午11:10
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function orderAttr()
    {
        $input = $this->request->input;
        $result = $this->orderService->orderAttr($input);
        return app_response(200, $result);
    }

    /**
     * 删除工单与工单项目
     * User: zhouyao
     * Date: 2018/9/12
     * Time: 下午11:15
     * @return \think\response\Json
     * @throws \app\common\exception\AppException
     */
    public function delete()
    {
        $input = $this->request->input;
        $result = $this->orderService->delete($input);
        return app_response(200, $result ? '操作成功' : '操作失败');
    }

    /**
     * @author zws
     *获取订单检测项目结果
     * @return \think\response\Json
     */
    public function orderProject()
    {
        $input = $this->request->input;
        $result = $this->orderService->orderProject($input);
        return app_response(200, $result);
    }
}